package com.gitee.wsl.console

/*
import android.graphics.Bitmap


object Image {
	*/
/**
	 * 将bitmap图转换为头四位有宽高的光栅位图
	 *//*

	fun getBytesFromBitMap(bitmap: Bitmap): ByteArray {
		val width = bitmap.width
		val height = bitmap.height
		val bw = (width - 1) / 8 + 1
		val rv = ByteArray(height * bw + 4)
		rv[0] = bw.toByte() //xL
		rv[1] = (bw shr 8).toByte() //xH
		rv[2] = height.toByte()
		rv[3] = (height shr 8).toByte()
		val pixels = IntArray(width * height)
		bitmap.getPixels(pixels, 0, width, 0, 0, width, height)
		for (i in 0 until height) {
			for (j in 0 until width) {
				val clr = pixels[width * i + j]
				val red = clr and 0x00ff0000 shr 16
				val green = clr and 0x0000ff00 shr 8
				val blue = clr and 0x000000ff
				val gray = RGB2Gray(red, green, blue)
				rv[bw * i + j / 8 + 4] =
					(rv[bw * i + j / 8 + 4].toInt() or (gray.toInt() shl 7) - j % 8).toByte()
			}
		}
		return rv
	}

	*/
/**
	 * 将bitmap转成按mode指定的N点行数据
	 *//*

	fun getBytesFromBitMap(bitmap: Bitmap, mode: Int): ByteArray? {
		val width = bitmap.width
		val height = bitmap.height
		val pixels = IntArray(width * height)
		return if (mode == 0 || mode == 1) {
			val res = ByteArray(width * height / 8 + 5 * height / 8)
			bitmap.getPixels(pixels, 0, width, 0, 0, width, height)
			for (i in 0 until height / 8) {
				res[0 + i * (width + 5)] = 0x1b
				res[1 + i * (width + 5)] = 0x2a
				res[2 + i * (width + 5)] = mode.toByte()
				res[3 + i * (width + 5)] = (width % 256).toByte()
				res[4 + i * (width + 5)] = (width / 256).toByte()
				for (j in 0 until width) {
					var gray: Byte = 0
					for (m in 0..7) {
						val clr = pixels[j + width * (i * 8 + m)]
						val red = clr and 0x00ff0000 shr 16
						val green = clr and 0x0000ff00 shr 8
						val blue = clr and 0x000000ff
						gray =
							(RGB2Gray(red, green, blue).toInt() shl 7 - m or gray.toInt()).toByte()
					}
					res[5 + j + i * (width + 5)] = gray
				}
			}
			res
		} else if (mode == 32 || mode == 33) {
			val res = ByteArray(width * height / 8 + 5 * height / 24)
			bitmap.getPixels(pixels, 0, width, 0, 0, width, height)
			for (i in 0 until height / 24) {
				res[0 + i * (width * 3 + 5)] = 0x1b
				res[1 + i * (width * 3 + 5)] = 0x2a
				res[2 + i * (width * 3 + 5)] = mode.toByte()
				res[3 + i * (width * 3 + 5)] = (width % 256).toByte()
				res[4 + i * (width * 3 + 5)] = (width / 256).toByte()
				for (j in 0 until width) {
					for (n in 0..2) {
						var gray: Byte = 0
						for (m in 0..7) {
							val clr = pixels[j + width * (i * 24 + m + n * 8)]
							val red = clr and 0x00ff0000 shr 16
							val green = clr and 0x0000ff00 shr 8
							val blue = clr and 0x000000ff
							gray = (RGB2Gray(red, green, blue).toInt() shl 7 - m or gray.toInt()).toByte()
						}
						res[5 + j * 3 + i * (width * 3 + 5) + n] = gray
					}
				}
			}
			res
		} else {
			byteArrayOf(0x0A)
		}
	}


	private fun RGB2Gray(r: Int, g: Int, b: Int): Byte {
		return if (((0.29900 * r + 0.58700 * g + 0.11400 * b).toInt() < 200)) 1.toByte() else 0.toByte()
	}

}*/
